/***
	公共方法
***/
//配置参数及方法
var user = JSON.parse(sessionStorage.getItem("backUserInfo"));
var yj = {
	//控制跳转   url格式:html/index.html"
	goPage:function(url){
		var str = location.pathname;
		var index = str.indexOf('html') + 4;
		var path  = str.substring(0,index);
		location.href =  location.protocol + '//' + location.host + path + url; 
	},
	//取url参数
	getUrlParam:function(name){
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
	}
};
function getMyDate(str){
		var oDate = new Date(str),
		oYear = oDate.getFullYear(),
		oMonth = oDate.getMonth()+1,
		oDay = oDate.getDate(),
		oHour = oDate.getHours(),
		oMin = oDate.getMinutes(),
		oSen = oDate.getSeconds(),
		oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间
		return oTime;
	};
	function getzf(num){
          if(parseInt(num) < 10){
              num = '0'+num;
          }
          return num;
    }
$(function () {
	//控制菜单跳转
	$(".sidebar-menu").on('click','li[data-href]',function(){
		var href = $(this).data("href");
		yj.goPage(href);
	});
	//代练后台
	$(".sidebar-menu li.treeview").eq(0).find(".treeview-menu").html("<li data-href='/PowerLevel/Information.html'><a><i class='fa fa-circle-o'></i>基础信息配置</a></li><li data-href='/PowerLevel/game.html'><a><i class='fa fa-circle-o'></i>游戏配置</a></li><li data-href='/PowerLevel/CustomerService.html'><a><i class='fa fa-circle-o'></i>客服聊天</a></li><li data-href='/PowerLevel/PowerLevelingOrder.html'><a><i class='fa fa-circle-o'></i>代练订单</a></li><li data-href='/PowerLevel/comment.html'><a><i class='fa fa-circle-o'></i>评价</a></li>");
	//选中菜单
	$(".sidebar-menu li.treeview").eq($("body").attr("data-treeview")).addClass("active").find(".treeview-menu").children("li").eq($("body").attr("data-treeview-menu")).addClass("active");
    //图片上传
	function fileupload(input,img,photoCover){
		var fileObj = document.getElementById(input).files[0];
		$.ajax({
			url:'http://39.106.145.173:8087/leveling/getToken.json',
			type:'POST',
			async:true,
			data:{
			},
			dataType: "json",
			success: function(data){
				var form = new FormData;
				form.append("file",fileObj);
				form.append("key",new Date().getTime()+".jpg");
				form.append("token",data.t.token);
				var domian=data.t.domain;
				$.ajax({
					url:'http://up.qiniu.com',
					type: 'POST',
					data:form,
					async: false,
					cache: false,
					contentType: false,
					processData: false,
					dataType: "json",
					success: function(data) {
					   $("."+img).html("<img src='"+domian+"/"+data.key+"'/>")	
					   $("#"+photoCover).val(""+domian+"/"+data.key+"");
					},
				});	
			}
	    });				
	}
	$("#lefile1").change(
	  function(){
		 fileupload("lefile1","imgfile1","photoCover1")
	  }
	)
	$("#lefile2").change(
	  function(){
		 fileupload("lefile2","imgfile2","photoCover2")
	  }
	)
	$("#lefile3").change(
	  function(){
		 fileupload("lefile3","imgfile3","photoCover3")
	  }
	)
	//获得登录信息
	if(user==null){
		window.location.href ='../../../PowerLevellogin.html';
	}else{
		$(".skin-blue .main-header .navbar").append("<div class='userinfo'>欢迎您，<span>"+user.levelingAccount+"</span>，<a id='logout'>退出登录</a></div>")
	}
	//退出登录
	$("#logout").click(function(){
	   sessionStorage.removeItem("backUserInfo");
	   window.location.href ='../../../PowerLevellogin.html';
	});
})